<!-- 代码已包含 CSS：使用 TailwindCSS , 安装 TailwindCSS 后方可看到布局样式效果 -->

<template>
  <div class="app-container">
    <div class="search-bar">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="80">
        <el-form-item label="常量" prop="codeType">
          <el-select
            v-model="queryParams.codeType"
            @change="handleSearch"
            placeholder="请输入常量"
            class="!w-[192px]"
            clearable
          >
            <el-option
              v-for="item in contractList"
              :key="item.codeValue"
              :label="item.codeName"
              :value="item.codeValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="refresh" @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-card shadow="never" class="p0">
      <el-table
        v-loading="loading"
        show-overflow-tooltip
        :tooltip-formatter="tableRowFormatter"
        :data="tableData"
      >
        <el-table-column prop="codeName" label="常量名称" />
        <el-table-column prop="codeType" label="常量类型" />
        <el-table-column prop="codeValue" label="常量值"></el-table-column>

        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column prop="remark" label="备注"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { Search, DataLine } from "@element-plus/icons-vue";
import configApi, { ConfigType } from "@/api/config/config";
import { tableRowFormatter } from "@/utils/index";
// 加载loading
const loading = ref(false);
interface CustomerReportPageQuery {
  codeType?: string;
}

const queryParams: CustomerReportPageQuery = reactive({});

const contractList = ref<any[]>([]);
function getContractList() {
  configApi.getConfigListByType(ConfigType.FINAL_CODE).then((res) => {
    console.log(res);
    contractList.value = res;
  });
}
const handleReset = () => {
  queryParams.codeType = "";
};
const typeOptions = [
  { value: "package", label: "包装材料" },
  { value: "product", label: "产品类型" },
  { value: "status", label: "状态类型" },
];

const tableData = ref([]);

const handleSearch = (val: any) => {
  console.log(val);
  // 实现搜索逻辑
  configApi.getConfigListByType(val).then((res) => {
    console.log(res);
    tableData.value = res as any;
    // contractList.value = res;
  });
};

onMounted(() => {
  getContractList();
});
</script>

<style scoped>
.el-table {
  --el-table-border-color: #e5e7eb;
  --el-table-header-bg-color: #f9fafb;
  --el-table-row-hover-bg-color: #f3f4f6;
}

.el-pagination {
  --el-pagination-button-bg-color: white;
  --el-pagination-hover-color: #1d4ed8;
}

/* 移除number类型input的上下箭头 */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}
</style>
